/*     */ package com.zimbra.cs.service.mail;
/*     */ 
/*     */ import com.zimbra.client.ZMailbox;
/*     */ import com.zimbra.client.ZMailbox.Options;
/*     */ import com.zimbra.common.account.Key.AccountBy;
/*     */ import com.zimbra.common.auth.ZAuthToken;
/*     */ import com.zimbra.common.calendar.ICalTimeZone;
/*     */ import com.zimbra.common.calendar.ParsedDateTime;
/*     */ import com.zimbra.common.calendar.TimeZoneMap;
/*     */ import com.zimbra.common.calendar.ZCalendar.ZVCalendar;
/*     */ import com.zimbra.common.mime.shim.JavaMailInternetAddress;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.soap.Element;
/*     */ import com.zimbra.common.soap.MailConstants;
/*     */ import com.zimbra.common.soap.SoapProtocol;
/*     */ import com.zimbra.common.util.L10nUtil;
/*     */ import com.zimbra.common.util.L10nUtil.MsgKey;
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.common.util.ZimbraLog;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.AuthToken;
/*     */ import com.zimbra.cs.account.CalendarResource;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.mailbox.CalendarItem;
/*     */ import com.zimbra.cs.mailbox.MailItem.Type;
/*     */ import com.zimbra.cs.mailbox.MailSender;
/*     */ import com.zimbra.cs.mailbox.MailServiceException;
/*     */ import com.zimbra.cs.mailbox.MailServiceException.NoSuchItemException;
/*     */ import com.zimbra.cs.mailbox.Mailbox;
/*     */ import com.zimbra.cs.mailbox.Mailbox.AddInviteData;
/*     */ import com.zimbra.cs.mailbox.Message;
/*     */ import com.zimbra.cs.mailbox.Message.CalendarItemInfo;
/*     */ import com.zimbra.cs.mailbox.OperationContext;
/*     */ import com.zimbra.cs.mailbox.calendar.CalendarMailSender;
/*     */ import com.zimbra.cs.mailbox.calendar.CalendarMailSender.Verb;
/*     */ import com.zimbra.cs.mailbox.calendar.Invite;
/*     */ import com.zimbra.cs.mailbox.calendar.RecurId;
/*     */ import com.zimbra.cs.mailbox.calendar.ZAttendee;
/*     */ import com.zimbra.cs.mime.ParsedMessage;
/*     */ import com.zimbra.cs.service.AuthProvider;
/*     */ import com.zimbra.cs.service.util.ItemId;
/*     */ import com.zimbra.cs.service.util.ItemIdFormatter;
/*     */ import com.zimbra.cs.util.AccountUtil;
/*     */ import com.zimbra.soap.ZimbraSoapContext;
/*     */ import java.util.Locale;
/*     */ import java.util.Map;
/*     */ import javax.mail.internet.AddressException;
/*     */ import javax.mail.internet.InternetAddress;
/*     */ import javax.mail.internet.MimeBodyPart;
/*     */ import javax.mail.internet.MimeMessage;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class SendInviteReply
/*     */   extends CalendarRequest
/*     */ {
/*  75 */   private static final String[] TARGET_PATH = { "id" };
/*     */   
/*     */   protected String[] getProxiedIdPath(Element request) {
/*  78 */     return TARGET_PATH;
/*     */   }
/*     */   
/*  81 */   protected boolean checkMountpointProxy(Element request) { return false; }
/*     */   
/*     */   public Element handle(Element request, Map<String, Object> context) throws ServiceException
/*     */   {
/*  85 */     ZimbraSoapContext zsc = getZimbraSoapContext(context);
/*  86 */     Mailbox mbox = getRequestedMailbox(zsc);
/*  87 */     Account acct = getRequestedAccount(zsc);
/*  88 */     Account authAcct = getAuthenticatedAccount(zsc);
/*  89 */     boolean isAdmin = zsc.isUsingAdminPrivileges();
/*  90 */     OperationContext octxt = getOperationContext(zsc, context);
/*     */     
/*  92 */     boolean onBehalfOf = isOnBehalfOfRequest(zsc);
/*     */     
/*  94 */     ItemId iid = new ItemId(request.getAttribute("id"), zsc);
/*  95 */     int compNum = (int)request.getAttributeLong("compNum");
/*     */     
/*  97 */     String verbStr = request.getAttribute("verb");
/*  98 */     CalendarMailSender.Verb verb = CalendarMailSender.parseVerb(verbStr);
/*  99 */     boolean isDecline = CalendarMailSender.VERB_DECLINE.equals(verb);
/*     */     
/* 101 */     boolean updateOrg = request.getAttributeBool("updateOrganizer", true);
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 107 */     String identityId = request.getAttribute("idnt", null);
/* 108 */     if (identityId == null) {
/* 109 */       Element msgElem = request.getOptionalElement("m");
/* 110 */       if (msgElem != null) {
/* 111 */         identityId = msgElem.getAttribute("idnt", null);
/*     */       }
/*     */     }
/* 114 */     Element response = getResponseElement(zsc);
/*     */     
/* 116 */     boolean intendedForMe = true;
/* 117 */     Invite oldInv = null;
/*     */     
/*     */ 
/* 120 */     CalendarItem calItem = null;
/* 121 */     boolean wasInTrash = false;
/*     */     
/*     */     int inviteMsgId;
/*     */     
/* 125 */     if (iid.hasSubpart())
/*     */     {
/* 127 */       int calItemId = iid.getId();
/* 128 */       int inviteMsgId = iid.getSubpartId();
/* 129 */       calItem = safeGetCalendarItemById(mbox, octxt, iid.getId());
/* 130 */       if (calItem == null)
/* 131 */         throw MailServiceException.NO_SUCH_CALITEM(iid.toString(), "Could not find calendar item");
/* 132 */       oldInv = calItem.getInvite(inviteMsgId, compNum);
/*     */     }
/*     */     else {
/* 135 */       inviteMsgId = iid.getId();
/* 136 */       Message msg = mbox.getMessageById(octxt, inviteMsgId);
/* 137 */       Message.CalendarItemInfo info = msg.getCalendarItemInfo(compNum);
/* 138 */       if (info == null) {
/* 139 */         throw MailServiceException.NO_SUCH_CALITEM(iid.toString(), "Could not find calendar item");
/*     */       }
/* 141 */       String intendedFor = msg.getCalendarIntendedFor();
/* 142 */       Account intendedAcct = null;
/* 143 */       if (intendedFor != null) {
/*     */         try {
/* 145 */           InternetAddress intendedForAddr = new JavaMailInternetAddress(intendedFor);
/* 146 */           intendedAcct = Provisioning.getInstance().get(Key.AccountBy.name, intendedForAddr.getAddress());
/*     */         } catch (AddressException e) {
/* 148 */           throw ServiceException.INVALID_REQUEST("The intended account " + intendedFor + " is invalid", e);
/*     */         }
/* 150 */         if (intendedAcct == null) {
/* 151 */           throw ServiceException.INVALID_REQUEST("The intended account " + intendedFor + " was not found", null);
/*     */         }
/*     */         
/* 154 */         if (intendedAcct.equals(mbox.getAccount())) {
/* 155 */           intendedAcct = null;
/*     */         } else {
/* 157 */           intendedForMe = false;
/*     */         }
/*     */       }
/* 160 */       if (intendedAcct != null)
/*     */       {
/* 162 */         ZimbraLog.calendar.info("<SendInviteReply> (remote mbox) id=%s, verb=%s, notifyOrg=%s", new Object[] { new ItemIdFormatter(zsc).formatItemId(iid), verb.toString(), Boolean.toString(updateOrg) });
/*     */         
/*     */ 
/*     */ 
/*     */ 
/* 167 */         calItem = null;
/* 168 */         int calItemId = 0;
/* 169 */         ZMailbox zmbx = getRemoteZMailbox(octxt, authAcct, intendedAcct);
/*     */         
/* 171 */         AddInviteResult addInviteResult = sendAddInvite(zmbx, octxt, msg);
/* 172 */         if (addInviteResult == null) {
/* 173 */           throw MailServiceException.INVITE_OUT_OF_DATE(iid.toString());
/*     */         }
/*     */         
/* 176 */         remoteSendInviteReply(zmbx, request, addInviteResult);
/*     */ 
/*     */       }
/* 179 */       else if (info.getInvite() != null) {
/* 180 */         calItem = mbox.getCalendarItemByUid(octxt, info.getInvite().getUid());
/* 181 */         wasInTrash = (calItem != null) && (calItem.inTrash());
/*     */         
/* 183 */         if ((calItem != null) && (!wasInTrash)) {
/* 184 */           Invite newInv = info.getInvite();
/*     */           
/* 186 */           Invite curr = calItem.getInvite(newInv.getRecurId());
/* 187 */           if ((curr != null) && (!newInv.isSameOrNewerVersion(curr))) {
/* 188 */             throw MailServiceException.INVITE_OUT_OF_DATE(iid.toString());
/*     */           }
/*     */         }
/* 191 */         Invite inv = info.getInvite().newCopy();
/* 192 */         Invite.setDefaultAlarm(inv, acct);
/* 193 */         inv.setMailItemId(inviteMsgId);
/*     */         
/*     */ 
/*     */ 
/*     */         int calItemId;
/*     */         
/*     */ 
/* 200 */         if ((calItem != null) || (!isDecline))
/*     */         {
/*     */ 
/* 203 */           boolean untrashing = (wasInTrash) && (!isDecline);
/* 204 */           int folder; int folder; if ((calItem == null) || (untrashing))
/*     */           {
/*     */ 
/*     */ 
/* 208 */             folder = inv.isTodo() ? 15 : 10;
/*     */           } else {
/* 210 */             folder = calItem.getFolderId();
/*     */           }
/* 212 */           ParsedMessage pm = new ParsedMessage(msg.getMimeMessage(false), false);
/* 213 */           Mailbox.AddInviteData aid = mbox.addInvite(octxt, inv, folder, pm, false, untrashing, true);
/* 214 */           if (aid == null)
/* 215 */             throw ServiceException.FAILURE("Could not create/update calendar item", null);
/* 216 */           int calItemId = aid.calItemId;
/*     */           
/* 218 */           calItem = safeGetCalendarItemById(mbox, octxt, aid.calItemId);
/* 219 */           if (calItem == null)
/* 220 */             throw ServiceException.FAILURE("Could not refetch created/updated calendar item", null);
/*     */         } else {
/* 222 */           calItemId = 0;
/*     */         }
/* 224 */         oldInv = inv;
/* 225 */       } else if (info.calItemCreated())
/*     */       {
/* 227 */         calItem = safeGetCalendarItemById(mbox, octxt, info.getCalendarItemId());
/* 228 */         if (calItem == null)
/* 229 */           throw ServiceException.FAILURE("Missing invite data", null);
/* 230 */         int calItemId = info.getCalendarItemId().getId();
/* 231 */         wasInTrash = calItem.inTrash();
/* 232 */         oldInv = calItem.getInvite(inviteMsgId, compNum);
/*     */       } else {
/* 234 */         throw ServiceException.FAILURE("Missing invite data", null);
/*     */       }
/*     */     }
/*     */     
/*     */     int calItemId;
/* 239 */     if (intendedForMe) {
/* 240 */       if (oldInv == null) {
/* 241 */         throw MailServiceException.INVITE_OUT_OF_DATE(iid.toString());
/*     */       }
/* 243 */       if ((calItem != null) && ((mbox.getEffectivePermissions(octxt, calItemId, MailItem.Type.UNKNOWN) & 0x10) == 0)) {
/* 244 */         throw ServiceException.PERM_DENIED("You do not have ACTION rights for CalendarItem " + calItemId);
/*     */       }
/*     */       
/*     */ 
/*     */ 
/* 249 */       boolean allowPrivateAccess = calItem != null ? calItem.allowPrivateAccess(authAcct, isAdmin) : true;
/* 250 */       boolean isCalendarResource = acct instanceof CalendarResource;
/* 251 */       if ((!allowPrivateAccess) && (!oldInv.isPublic()) && (!isCalendarResource)) {
/* 252 */         throw ServiceException.PERM_DENIED("Cannot reply to a private appointment/task on behalf of another user");
/*     */       }
/*     */       
/* 255 */       Element exc = request.getOptionalElement("exceptId");
/* 256 */       ParsedDateTime exceptDt = null;
/* 257 */       if (exc != null) {
/* 258 */         TimeZoneMap tzmap = oldInv.getTimeZoneMap();
/* 259 */         Element tzElem = request.getOptionalElement("tz");
/* 260 */         ICalTimeZone tz = null;
/* 261 */         if (tzElem != null) {
/* 262 */           tz = CalendarUtils.parseTzElement(tzElem);
/* 263 */           tzmap.add(tz);
/*     */         }
/* 265 */         exceptDt = CalendarUtils.parseDateTime(exc, tzmap);
/* 266 */       } else if (oldInv.hasRecurId()) {
/* 267 */         exceptDt = oldInv.getRecurId().getDt();
/*     */       }
/*     */       
/*     */ 
/* 271 */       String calItemIdStr = calItem != null ? Integer.toString(calItem.getId()) : "none";
/* 272 */       String folderIdStr = calItem != null ? Integer.toString(calItem.getFolderId()) : "none";
/* 273 */       if (exceptDt == null) {
/* 274 */         ZimbraLog.calendar.info("<SendInviteReply> id=%s, folderId=%s, verb=%s, notifyOrg=%s, subject=\"%s\", UID=%s", new Object[] { calItemIdStr, folderIdStr, verb.toString(), Boolean.toString(updateOrg), oldInv.isPublic() ? oldInv.getName() : "(private)", oldInv.getUid() });
/*     */       }
/*     */       else
/*     */       {
/* 278 */         ZimbraLog.calendar.info("<SendInviteReply> id=%s, folderId=%s, verb=%s, notifyOrg=%s, subject=\"%s\", UID=%s, recurId=%s", new Object[] { calItemIdStr, folderIdStr, verb.toString(), Boolean.toString(updateOrg), oldInv.isPublic() ? oldInv.getName() : "(private)", oldInv.getUid(), exceptDt.getUtcString() });
/*     */       }
/*     */       
/*     */ 
/*     */ 
/*     */ 
/* 284 */       if ((calItem != null) && (oldInv.isRecurrence()) && (exceptDt != null)) {
/* 285 */         Invite localException = oldInv.makeInstanceInvite(exceptDt);
/* 286 */         long now = octxt != null ? octxt.getTimestamp() : System.currentTimeMillis();
/* 287 */         localException.setDtStamp(now);
/*     */         
/* 289 */         String partStat = verb.getXmlPartStat();
/* 290 */         localException.setPartStat(partStat);
/* 291 */         ZAttendee at = localException.getMatchingAttendee(acct, identityId);
/* 292 */         if (at != null) {
/* 293 */           at.setPartStat(partStat);
/*     */         }
/*     */         
/* 296 */         MimeMessage mmInv = calItem.getSubpartMessage(oldInv.getMailItemId());
/* 297 */         ParsedMessage pm = mmInv != null ? new ParsedMessage(mmInv, false) : null;
/*     */         
/*     */ 
/* 300 */         boolean untrashing = (wasInTrash) && (!isDecline);
/* 301 */         int folder; int folder; if (untrashing)
/*     */         {
/*     */ 
/* 304 */           folder = localException.isTodo() ? 15 : 10;
/*     */         } else {
/* 306 */           folder = calItem.getFolderId();
/*     */         }
/* 308 */         mbox.addInvite(octxt, localException, folder, pm, true, untrashing, true);
/*     */         
/*     */ 
/* 311 */         calItem = safeGetCalendarItemById(mbox, octxt, calItemId);
/* 312 */         if (calItem == null)
/* 313 */           throw MailServiceException.NO_SUCH_CALITEM(iid.toString(), "Could not find calendar item");
/* 314 */         oldInv = calItem.getInvite(new RecurId(exceptDt, RecurId.RANGE_NONE));
/*     */       }
/*     */       
/* 317 */       if ((updateOrg) && (oldInv.hasOrganizer()))
/*     */       {
/* 319 */         Account organizer = oldInv.getOrganizerAccount();
/* 320 */         Locale locale; Locale locale; if (organizer != null) {
/* 321 */           locale = organizer.getLocale();
/*     */         } else
/* 323 */           locale = !onBehalfOf ? acct.getLocale() : authAcct.getLocale();
/*     */         String subject;
/* 325 */         String subject; if ((!allowPrivateAccess) && (!oldInv.isPublic())) {
/* 326 */           subject = L10nUtil.getMessage(L10nUtil.MsgKey.calendarSubjectWithheld, locale, new Object[0]);
/*     */         } else
/* 328 */           subject = oldInv.getName();
/* 329 */         String replySubject = CalendarMailSender.getReplySubject(verb, subject, locale);
/*     */         
/*     */ 
/* 332 */         CalendarRequest.CalSendData csd = new CalendarRequest.CalSendData();
/* 333 */         csd.mOrigId = new ItemId(mbox, oldInv.getMailItemId());
/* 334 */         csd.mReplyType = MailSender.MSGTYPE_REPLY;
/* 335 */         csd.mInvite = CalendarMailSender.replyToInvite(acct, identityId, authAcct, onBehalfOf, allowPrivateAccess, oldInv, verb, replySubject, exceptDt);
/*     */         
/* 337 */         ZCalendar.ZVCalendar iCal = csd.mInvite.newToICalendar(true);
/*     */         
/* 339 */         ParseMimeMessage.MimeMessageData parsedMessageData = new ParseMimeMessage.MimeMessageData();
/*     */         
/*     */ 
/* 342 */         Element msgElem = request.getOptionalElement("m");
/* 343 */         if (msgElem != null) {
/* 344 */           String text = ParseMimeMessage.getTextPlainContent(msgElem);
/* 345 */           String html = ParseMimeMessage.getTextHtmlContent(msgElem);
/* 346 */           iCal.addDescription(text, html);
/*     */           
/* 348 */           MimeBodyPart[] mbps = new MimeBodyPart[1];
/* 349 */           mbps[0] = CalendarMailSender.makeICalIntoMimePart(iCal);
/*     */           
/*     */ 
/*     */ 
/*     */ 
/* 354 */           csd.mMm = ParseMimeMessage.parseMimeMsgSoap(zsc, octxt, mbox, msgElem, mbps, ParseMimeMessage.NO_INV_ALLOWED_PARSER, parsedMessageData);
/*     */ 
/*     */ 
/*     */         }
/* 358 */         else if (!(acct instanceof CalendarResource)) {
/* 359 */           csd.mMm = CalendarMailSender.createDefaultReply(acct, identityId, authAcct, identityId, isAdmin, onBehalfOf, calItem, oldInv, null, replySubject, verb, null, iCal);
/*     */ 
/*     */         }
/*     */         else
/*     */         {
/* 364 */           RecurId rid = oldInv.getRecurId();
/* 365 */           ParsedDateTime ridDt = rid != null ? rid.getDt() : null;
/* 366 */           Invite replyInv = CalendarMailSender.replyToInvite(acct, authAcct, onBehalfOf, allowPrivateAccess, oldInv, verb, replySubject, ridDt);
/*     */           
/*     */ 
/* 369 */           MimeMessage mmInv = calItem.getSubpartMessage(oldInv.getMailItemId());
/* 370 */           csd.mMm = CalendarMailSender.createResourceAutoReply(octxt, identityId, identityId, mbox, verb, false, null, calItem, oldInv, new Invite[] { replyInv }, mmInv, true);
/*     */         }
/*     */         
/*     */         int apptFolderId;
/*     */         
/*     */         int apptFolderId;
/*     */         
/* 377 */         if (calItem != null) {
/* 378 */           apptFolderId = calItem.getFolderId();
/*     */         } else
/* 380 */           apptFolderId = oldInv.isTodo() ? 15 : 10;
/* 381 */         CalendarRequest.MailSendQueue sendQueue = new CalendarRequest.MailSendQueue();
/*     */         try {
/* 383 */           sendCalendarMessage(zsc, octxt, apptFolderId, acct, mbox, csd, response, sendQueue);
/*     */         } finally {
/* 385 */           sendQueue.send();
/*     */         }
/*     */       }
/*     */       
/* 389 */       RecurId recurId = null;
/* 390 */       if (exceptDt != null) {
/* 391 */         recurId = new RecurId(exceptDt, RecurId.RANGE_NONE);
/*     */       }
/* 393 */       ZAttendee me = oldInv.getMatchingAttendee(acct);
/* 394 */       String cnStr = null;
/* 395 */       String addressStr = acct.getName();
/* 396 */       String role = "OPT";
/* 397 */       int seqNo = oldInv.getSeqNo();
/* 398 */       long dtStamp = oldInv.getDTStamp();
/* 399 */       if (me != null) {
/* 400 */         if (me.hasCn()) {
/* 401 */           cnStr = me.getCn();
/*     */         }
/* 403 */         addressStr = me.getAddress();
/* 404 */         if (me.hasRole()) {
/* 405 */           role = me.getRole();
/*     */         }
/*     */       }
/*     */       
/* 409 */       if (calItem != null) {
/* 410 */         mbox.modifyPartStat(octxt, calItemId, recurId, cnStr, addressStr, null, role, verb.getXmlPartStat(), Boolean.FALSE, seqNo, dtStamp);
/*     */       }
/*     */     }
/*     */     
/* 414 */     if (deleteInviteOnReply(acct)) {
/*     */       try {
/* 416 */         if (onBehalfOf)
/*     */         {
/*     */ 
/*     */ 
/* 420 */           octxt = new OperationContext(mbox);
/*     */         }
/* 422 */         mbox.move(octxt, inviteMsgId, MailItem.Type.MESSAGE, 3);
/*     */       } catch (MailServiceException.NoSuchItemException nsie) {
/* 424 */         ZimbraLog.calendar.debug("can't move nonexistent invite to Trash: " + inviteMsgId);
/*     */       }
/*     */     }
/*     */     
/* 428 */     return response;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/* 435 */   protected boolean deleteInviteOnReply(Account acct)
/* 435 */     throws ServiceException { return acct.isPrefDeleteInviteOnReply(); }
/*     */   
/*     */   private static class AddInviteResult {
/*     */     private final int mCalItemId;
/*     */     private final int mInvId;
/*     */     private final int mCompNum;
/*     */     
/*     */     public AddInviteResult(int calItemId, int invId, int compNum) {
/* 443 */       this.mCalItemId = calItemId;
/* 444 */       this.mInvId = invId;
/* 445 */       this.mCompNum = compNum; }
/*     */     
/* 447 */     public int getCalItemId() { return this.mCalItemId; }
/* 448 */     public int getInvId() { return this.mInvId; }
/* 449 */     public int getCompNum() { return this.mCompNum; }
/*     */   }
/*     */   
/*     */   private static ZMailbox getRemoteZMailbox(OperationContext octxt, Account authAcct, Account targetAcct) throws ServiceException
/*     */   {
/* 454 */     AuthToken authToken = null;
/* 455 */     if (octxt != null)
/* 456 */       authToken = AuthToken.getCsrfUnsecuredAuthToken(octxt.getAuthToken());
/* 457 */     if (authToken == null)
/* 458 */       authToken = AuthProvider.getAuthToken(authAcct);
/* 459 */     String pxyAuthToken = authToken.getProxyAuthToken();
/* 460 */     ZAuthToken zat = pxyAuthToken == null ? authToken.toZAuthToken() : new ZAuthToken(pxyAuthToken);
/*     */     
/* 462 */     ZMailbox.Options zoptions = new ZMailbox.Options(zat, AccountUtil.getSoapUri(targetAcct));
/* 463 */     zoptions.setNoSession(true);
/* 464 */     zoptions.setTargetAccount(targetAcct.getId());
/* 465 */     zoptions.setTargetAccountBy(Key.AccountBy.id);
/* 466 */     return ZMailbox.getMailbox(zoptions);
/*     */   }
/*     */   
/*     */   private static AddInviteResult sendAddInvite(ZMailbox zmbx, OperationContext octxt, Message msg) throws ServiceException
/*     */   {
/* 471 */     ItemIdFormatter ifmt = new ItemIdFormatter();
/* 472 */     Element addInvite = Element.create(SoapProtocol.SoapJS, MailConstants.ADD_APPOINTMENT_INVITE_REQUEST);
/* 473 */     ToXML.encodeMessageAsMIME(addInvite, ifmt, octxt, msg, null, true, false);
/* 474 */     Element response = zmbx.invoke(addInvite);
/* 475 */     int calItemId = (int)response.getAttributeLong("calItemId", 0L);
/* 476 */     int invId = (int)response.getAttributeLong("invId", 0L);
/* 477 */     int compNum = (int)response.getAttributeLong("compNum", 0L);
/* 478 */     if (calItemId != 0) {
/* 479 */       return new AddInviteResult(calItemId, invId, compNum);
/*     */     }
/* 481 */     return null;
/*     */   }
/*     */   
/*     */   private static void remoteSendInviteReply(ZMailbox zmbx, Element origRequest, AddInviteResult ids) throws ServiceException
/*     */   {
/* 486 */     ItemIdFormatter ifmt = new ItemIdFormatter();
/* 487 */     Element req = origRequest.clone();
/* 488 */     req.detach();
/* 489 */     String idStr = ifmt.formatItemId(ids.getCalItemId(), ids.getInvId());
/* 490 */     req.addAttribute("id", idStr);
/* 491 */     req.addAttribute("compNum", ids.getCompNum());
/* 492 */     zmbx.invoke(req);
/*     */   }
/*     */   
/*     */ 
/*     */   private static CalendarItem safeGetCalendarItemById(Mailbox mbox, OperationContext octxt, ItemId calItemId)
/*     */     throws ServiceException
/*     */   {
/*     */     try
/*     */     {
/* 501 */       return mbox.getCalendarItemById(octxt, calItemId);
/*     */     } catch (MailServiceException e) {
/* 503 */       String code = e.getCode();
/* 504 */       if (("mail.NO_SUCH_ITEM".equals(code)) || ("mail.NO_SUCH_CALITEM".equals(code)) || ("mail.NO_SUCH_APPT".equals(code)) || ("mail.NO_SUCH_TASK".equals(code)))
/*     */       {
/*     */ 
/*     */ 
/* 508 */         return null;
/*     */       }
/* 510 */       throw e;
/*     */     }
/*     */   }
/*     */   
/*     */   private static CalendarItem safeGetCalendarItemById(Mailbox mbox, OperationContext octxt, int calItemId) throws ServiceException
/*     */   {
/*     */     try {
/* 517 */       return mbox.getCalendarItemById(octxt, calItemId);
/*     */     } catch (MailServiceException e) {
/* 519 */       String code = e.getCode();
/* 520 */       if (("mail.NO_SUCH_ITEM".equals(code)) || ("mail.NO_SUCH_CALITEM".equals(code)) || ("mail.NO_SUCH_APPT".equals(code)) || ("mail.NO_SUCH_TASK".equals(code)))
/*     */       {
/*     */ 
/*     */ 
/* 524 */         return null;
/*     */       }
/* 526 */       throw e;
/*     */     }
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/mail/SendInviteReply.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */